---
title: "Direct_mail_meta_analysis"
author: "Jose S. Gomez"
date: "4/8/2019"
output: html_document
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

#setup clean working environment, packages and data
```{r}
rm(list=ls())       # clear objects in memory
setwd("/Users/jge/Dropbox/GOTV IV (Andrew, Jose, Don)/Working Data/") # set working directory on Mac
#setwd("C:/Users/joses/Dropbox/GOTV IV (Andrew, Jose, Don)/Working Data/") # set working directory on Windows
library(foreign) 
library(metafor) # meta-analysis package

mail_data <- read.csv("GOTV IV Direct Mail Data (overall collapsed).csv")

mail_data$SoftSocialPressure <- ifelse(
  (mail_data$Author== "Gerber, Green, Larimer" & mail_data$Advocacy == 0 & mail_data$SocialPressure == 0), 1, 0)   #coding Soft social pressure in data used 
```

#Appendix B estimates in order of thier appearance within the book:
```{r}
#Non-partisan mailers that do not invoke social pressure
rma(yi = Meta_b[Advocacy == 0 & SocialPressure == 0 &studynum != 141 &studynum != 142], 
    sei= Meta_SE[Advocacy == 0 & SocialPressure == 0 &studynum != 141 &studynum != 142],     
    method = "DL", 
    data= mail_data)

############non advocacy no soft social pressure no gratitude ################

rma(yi = Meta_b[Advocacy == 0 & SocialPressure == 0 & SoftSocialPressure == 0 & Gratitude == 0 &studynum != 141 &studynum != 142],
    sei= Meta_SE[Advocacy == 0 & SocialPressure == 0 & SoftSocialPressure == 0 & Gratitude == 0 &studynum != 141 &studynum != 142],
    method = "DL", 
    data= mail_data)


#advocacy mailers that do not invoke social pressure
rma(yi = Meta_b[Advocacy == 1 & SocialPressure == 0 & studynum != 17], 
    sei= Meta_SE[Advocacy == 1 & SocialPressure == 0 & studynum != 17], 
    method = "DL", 
    data= mail_data) 

#Pooled social pressure estimates 
rma(yi = Meta_b[SocialPressure == 1], 
    sei= Meta_SE[SocialPressure == 1], 
    method = "DL", 
    data= mail_data) 
```